package mysql

import (
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"gorm.io/gorm"
)

type Medicine struct {
	gorm.Model
	Name    string `gorm:"type:varchar(30);comment:药品名称"`
	Big     string `gorm:"type:varchar(30);comment:规格"`
	Address string `gorm:"type:varchar(30);comment:生产厂商"`
	Shi     string `gorm:"type:varchar(30);comment:适应症"`
	Num     int    `gorm:"type:int(11);comment:用量"`
	Zhu     string `gorm:"type:varchar(30);comment:注意事项"`
	Typer   int    `gorm:"type:int(11);comment:类型"`
}

func (m *Medicine) MedicineAdd(db *gorm.DB) error {
	return db.Debug().Create(m).Error
}

func (m *Medicine) UpdateMedicine(db *gorm.DB) error {
	return db.Debug().Updates(m).Error
}
func MedicineList(db *gorm.DB) ([]*doctorrpc.MedicineList, error) {
	var list []*doctorrpc.MedicineList
	db.Debug().Model(&Medicine{}).Select(
		"name",
		"big",
		"address",
		"shi",
		"num",
		"zhu",
		"typer",
	).Find(&list)
	return list, err
}
